const app = getApp()

export default class LastMayday {
  palette() {
    return ({
      width: '550rpx',
      height: '1000rpx',
      background: '/utils/bg.png',
      views: [
        {
          type: 'text',
          text: "分享卡",
          css: [{
            top: `${startTop + 1 * gapSize}rpx`,
            fontWeight: 'bold',
          }, common, { left: '196rpx' }, {fontSize: '60rpx'}],
        },
        {
          type: 'image',
          url: app.globalData.userInfo.avatarUrl,
          css: {
            top: '266rpx',
            left: '220rpx',
            borderRadius: '60rpx',
            borderWidth: '6rpx',
            borderColor: 'gold',
            width: '120rpx',
            height: '120rpx',
          },
        },
        {
          type: 'text',
          text: app.globalData.userInfo.nickName,
          css: [{
            top: `${startTop + 5.2 * gapSize}rpx`,
            align: 'center',
            width: '300rpx',
          }, common, { left: '280rpx' }, { fontSize: '28rpx' }],
        },
        {
          type: 'text',
          text: '醉后不知天在水',
          css: [{
            top: `${startTop + 6.3 * gapSize}rpx`,
            align: 'center',
            width: '400rpx',
          }, common, { left: '280rpx' }, { fontSize: '30rpx' }],
        },
        {
          type: 'text',
          text: '满船清梦压星河',
          css: [{
            top: `${startTop + 7 * gapSize}rpx`,
            align: 'center',
            width: '400rpx',
          }, common, { left: '280rpx' }, { fontSize: '30rpx' }],
        },
        {
          type: 'text',
          text: '-桃之夭夭 灼灼其华-',
          css: [{
            top: `${startTop + 9.1 * gapSize}rpx`,
            align: 'center',
            width: '400rpx',
          }, common, { left: '280rpx' }, { fontSize: '24rpx' }],
        },
        {
          type: 'qrcode',
          content: 'https://gitee.com/ChengTransition/share.git',
          css: {
            bottom: '140rpx',
            left: '216rpx',
            color: 'skyblue',
            borderWidth: '2rpx',
            borderColor: 'yellowgreen',
            width: '120rpx',
            height: '120rpx',
          },
        },
        {
          type: 'text',
          text: '长按识别图中二维码',
          css: [{
            top: `${startTop + 12 * gapSize}rpx`,
            align: 'center',
            width: '400rpx',
            color: '#999'
          }, common, { left: '280rpx' }, { fontSize: '22rpx' }],
        },
      ],
    });
  }
}

const startTop = 50;
const startLeft = 20;
const gapSize = 70;
const common = {
  left: `${startLeft}rpx`,
  fontSize: '40rpx',
};

function _textDecoration(decoration, index, color) {
  return ({
    type: 'text',
    text: decoration,
    css: [{
      top: `${startTop + index * gapSize}rpx`,
      color: color,
      textDecoration: decoration,
    }, common],
  });
}

function _image(index, rotate, borderRadius) {
  return (
    {
      type: 'image',
      url: app.globalData.userInfo.avatarUrl,
      css: {
        top: `${startTop + 8.5 * gapSize}rpx`,
        left: `${startLeft + 160 * index}rpx`,
        width: '120rpx',
        height: '120rpx',
        rotate: rotate,
        borderRadius: borderRadius,
      },
    }
  );
}

function _des(index, content) {
  const des = {
    type: 'text',
    text: content,
    css: {
      fontSize: '22rpx',
      top: `${startTop + 8.5 * gapSize + 140}rpx`,
    },
  };
  if (index === 3) {
    des.css.right = '60rpx';
  } else {
    des.css.left = `${startLeft + 120 * index + 30}rpx`;
  }
  return des;
}
